﻿using CAN_Controller.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CAN_Controller
{
    class MachinePanel1 : Panel
    {
        public Label mLb;   //提示标签“ID : ”
        public Label mID_lb;    //存储ID
        public PictureBox mState_img;   //显示状态的图片
        public Button mOpen_btn;    //开按钮
        public Button mClose_btn;   //关按钮
        public Button mSetting_btn; //设置按钮

        public MachinePanel1()
        {
            mLb = new Label();
            mLb.SetBounds(5, 6, 29, 12);
            mLb.Text = "ID：";

            mID_lb = new Label();
            mLb.SetBounds(40, 6, 53, 12);
            mID_lb.Text = "NULL";

            mState_img = new PictureBox();
            mState_img.SetBounds(96, 3, 20, 20);
            mState_img.Image = Resources.none;

            mOpen_btn = new Button();
            mOpen_btn.SetBounds(122, 3, 75, 23);
            mOpen_btn.Click += button_Click;
            mOpen_btn.Tag = "open";

            mClose_btn = new Button();
            mClose_btn.SetBounds(122, 32, 75, 23);
            mClose_btn.Click += button_Click;
            mClose_btn.Tag = "close";

            mSetting_btn = new Button();
            mSetting_btn.SetBounds(122, 62, 75, 23);
            mSetting_btn.Click += button_Click;
            mSetting_btn.Tag = "setting";
        }

        public MachinePanel1(String ID_str)
        {
            SetClientSizeCore(200,100);
            BackColor = System.Drawing.Color.LightCoral;

            mLb = new Label();
            mLb.SetBounds(5, 6, 29, 12);
            mLb.Text = "ID：";
            Controls.Add(mLb);

            //将传入的ID赋值给Label.Text
            mID_lb = new Label();
            mLb.SetBounds(40, 6, 53, 12);
            mID_lb.Text = ID_str;
            Controls.Add(mID_lb);

            mState_img = new PictureBox();
            mState_img.SetBounds(96, 3, 20, 20);
            mState_img.Image = Resources.none;
            Controls.Add(mState_img);

            mOpen_btn = new Button();
            mOpen_btn.SetBounds(122, 3, 75, 23);
            mOpen_btn.Click += button_Click;
            mOpen_btn.Tag = "open";
            Controls.Add(mOpen_btn);

            mClose_btn = new Button();
            mClose_btn.SetBounds(122, 32, 75, 23);
            mClose_btn.Click += button_Click;
            mClose_btn.Tag = "close";
            Controls.Add(mClose_btn);

            mSetting_btn = new Button();
            mSetting_btn.SetBounds(122, 62, 75, 23);
            mSetting_btn.Click += button_Click;
            mSetting_btn.Tag = "setting";
            Controls.Add(mSetting_btn);
        }

        private void button_Click(object sender, EventArgs e)
        {
            switch (((Button)sender).Tag.ToString())
            {
                case "open":
                    {
                        mState_img.Image = Resources.open;
                    }break;
                case "close":
                    {
                        mState_img.Image = Resources.close;
                    }
                    break;
                case "setting":
                    {

                    }
                    break;
                default:break;
            }

        }
    }
}
